<?php

namespace App\Http\Validators;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;

class Request extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     * @return bool
     */
    public function authorize(){

        return true;
    }

    /**
     * 处理验证异常消息
     * @return void
     */
    protected function failedValidation(Validator $validator){
        throw (new HttpResponseException(response()->json([
            'code' =>  0,
            'msg' => $validator->errors()->first(),
        ])));
    }


    /**
     * 自定义 处理验证异常消息
     */
    protected function error($msg){
        throw (new HttpResponseException(response()->json([
            'code' =>  0,
            'msg' => $msg,
        ])));
    }
}
